package org.zfes.snowier.zbss.xzy.router.solution;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.zfes.snowier.core.data.DataSet;
import org.zfes.snowier.web.controller.BaseController;
import org.zfes.snowier.zbss.xzy.biz.solution.model.Algorithm;
import org.zfes.snowier.zbss.xzy.biz.solution.model.SolutionAlgorithm;
import org.zfes.snowier.zbss.xzy.biz.solution.service.ISolutionAlgorithmService;
import org.zfes.snowier.zbss.xzy.solution.SolutionAlgorithmSetDto;
import org.zfes.snowier.core.data.SelectVo;
@Controller 
@RequestMapping("/manager/solution/algorithm")
public class SolutionAlgorithmController implements BaseController {

	
	@Autowired
	private ISolutionAlgorithmService solutionAlgorithmService;
	
	//@RequiresPermissions(value="solutionAlgorithm:loadSolutionAlgorithmDataSet",desc="解决方案算法集列表")
    @RequestMapping(value="/loadSolutionAlgorithmDataSet", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
    public @ResponseBody  Object loadSolutionAlgorithmDataSet(@RequestBody Map<String,Object> params){
	    DataSet dataSet=  solutionAlgorithmService.loadSolutionAlgorithmDataSet(params);
	    return ajaxQuery("dataSet", dataSet);
    }
	
	//@RequiresPermissions(value="solutionAlgorithm:createSolutionAlgorithm",desc="解决方案算法集添加")
    @RequestMapping(value="/createSolutionAlgorithm", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
    public  @ResponseBody Object createSolutionAlgorithm(@RequestBody SolutionAlgorithm solutionAlgorithm){
		solutionAlgorithmService.createSolutionAlgorithm(solutionAlgorithm);
    	return ajaxDoneSuccess("数据操作成功 ");
    }
	
	//@RequiresPermissions(value="solutionAlgorithm:loadSolutionAlgorithm",desc="解决方案算法集加载")
    @RequestMapping(value="/loadSolutionAlgorithm/{id}", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
    public @ResponseBody  Object loadSolutionAlgorithm(@PathVariable("id")Long id){
		Optional<SolutionAlgorithm> ops = solutionAlgorithmService.loadSolutionAlgorithmById(id);
		return ajaxQuery("solutionAlgorithm",ops);
    }
	
	
	//@RequiresPermissions(value="solutionAlgorithm:deletSolutionAlgorithm",desc="解决方案算法集删除")
    @RequestMapping(value="/deleteSolutionAlgorithm/{id}", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
    public @ResponseBody  Object deleteSolutionAlgorithm(@PathVariable("id")Long id){
		solutionAlgorithmService.deleteSolutionAlgorithm(id);
		return ajaxDoneSuccess("数据操作成功 ");
    }

    
    
    @RequestMapping(value="/loadSolutionAlgorithmSelectVo", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
    public @ResponseBody  Object loadSolutionAlgorithmSelectVo(Long solutionId){
		 List<SelectVo>  ops = solutionAlgorithmService.loadSolutionAlgorithmSelectVo(solutionId);
		return ajaxQuery("selectVo",ops);
    }
    
    @RequestMapping(value="/setSolutionAlgorithms", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
    public @ResponseBody  Object setSolutionAlgorithms(@RequestBody SolutionAlgorithmSetDto solutionAlgorithm){
    	solutionAlgorithmService.setSolutionAlgorithms(solutionAlgorithm.getSolutionId(), solutionAlgorithm.getAlgorithmIds());
		return ajaxDoneSuccess("数据操作成功 ");
    }
    
    
    @RequestMapping(value="/loadAlgorithmsSolutionBinded", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
    public @ResponseBody  Object loadAlgorithmsSolutionBinded(Long solutionId){
		 List<Algorithm>  ops = solutionAlgorithmService.loadAlgorithmsSolutionBinded(solutionId);
		return ajaxQuery("algorithmList",ops);
    }
    
}